<template>
  <div>
    <el-row style="padding: 10px;" >
      <el-table :data="userList">
        <el-table-column
            label="用户头像"
            width="120px">
          <template slot-scope="scope">
              <el-image :src="'http://120.55.43.101:9090/img/'+scope.row.userImg" fit="fill" ></el-image>
<!--              <el-image :src="'http://localhost:9090/img/'+userList.userImg" fit="fill" ></el-image>-->
          </template>
        </el-table-column>
        <el-table-column label="用户名" prop="username"></el-table-column>
        <el-table-column label="用户密码" prop="password"></el-table-column>
        <el-table-column label="昵称" prop="nickname"></el-table-column>
        <el-table-column label="手机号" prop="userMobile"></el-table-column>
        <el-table-column label="性别" prop="userSex"></el-table-column>
        <el-table-column label="注册时间" prop="userRegtime" width="150px"></el-table-column>
        <el-table-column label="操作" fixed="right">
          <template slot-scope="scope">
            <el-button
                size="mini" @click="updateOne(scope.row.userId)"
                type="text" icon="el-icon-refresh">重置密码</el-button>
          </template>
        </el-table-column>
        <el-table-column fixed="right">
          <template slot-scope="scope">
            <el-button
                size="mini" @click="deleteOne(scope.row.userId)"
                type="text" icon="el-icon-delete">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[2, 5, 10, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
import axios from "axios";
import {baseURL} from "../../public/urlConfig";

export default {
  name: "UserAdmin",
  data(){
    return{
      pageSize:5,
      pageNum:1,
      total:0,
      userList:[],
      userImg:[],
      adminId:sessionStorage.getItem("adminId"),
    }
  },
  created() {
    this.load()
  },
  methods:{
    load(){
      axios.get(baseURL+"/user/page",{
        params: {
          current: this.pageNum,
          size: this.pageSize,}
      }).then(
          res=>{
            this.userList=res.data.records
            console.log(this.userList);
            this.total=res.data.total
          }
      )
      // axios.get(baseURL+"/user/userList").then(
      //     res=>{this.userList=res.data})
      // console.log(this.userList);
    },
    handleSizeChange(pageSize) {
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum
      this.load()
    },
    deleteOne(id){
      axios.delete(baseURL+"/user/"+id).then(
          res=>{
            if(res.data===true)this.$message.success("删除成功")
            else this.$message.error("删除失败")
            this.load()
          }
      )
    },
    updateOne(id){
      axios.post(baseURL+"/user/update/"+id).then(
          res=>{
            if(res.data===true)this.$message.success("修改成功")
            else this.$message.error("修改失败")
            this.load()
          }
      )
    },
  }
}
</script>

<style scoped>

</style>